package ${basePackage}.controller;
import ${basePackage}.utils.R;
import ${basePackage}.utils.PageUtil;
import ${basePackage}.pojo.${modelNameUpperCamel};
import ${basePackage}.service.${modelNameUpperCamel}Service;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
*
* @author ${author}
* @date ${date}
*/
@Slf4j
@RestController
@RequestMapping("${baseRequestMapping}")
@Api(tags = "${modelNameUpperCamel}Controller")
public class ${modelNameUpperCamel}Controller {
    @Resource
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @ApiOperation(value = "根据id获取信息")
    @GetMapping("/detail")
    public R detail(Integer id) {

        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id);
        return R.ok().data("${modelNameLowerCamel}",${modelNameLowerCamel});
    }

    @ApiOperation(value = "获取信息（list不分页）")
    @GetMapping("/list")
    public R list() {
        List<${modelNameUpperCamel}>  list = ${modelNameLowerCamel}Service.queryAll();
        return R.ok().data("list",list);
    }



    @ApiOperation(value = "获取信息（list分页）不带条件")
    @GetMapping("/listPages")
    public R listPages(Integer pageNum,Integer pageSize) {
        PageUtil<${modelNameUpperCamel}> pageUtils = ${modelNameLowerCamel}Service.findListAll(pageNum, pageSize);

        return R.ok().data("pageUtils",pageUtils);
    }

    @ApiOperation(value = "获取信息（list分页）带条件")
    @PostMapping("pageQueryByAll")
    public R pageQueryByAll(@RequestBody ${modelNameUpperCamel} ${modelNameLowerCamel}, Integer pageNum,Integer pageSize){
        PageUtil<${modelNameUpperCamel}> pageUtils = ${modelNameLowerCamel}Service.pageQueryByAll(pageNum, pageSize, ${modelNameLowerCamel});
        return R.ok().data("pageUtils",pageUtils);
    }

    @ApiOperation(value = "添加信息")
    @PostMapping("/add")
    public R add(${modelNameUpperCamel} ${modelNameLowerCamel}) {

        boolean b = ${modelNameLowerCamel}Service.save${modelNameUpperCamel}(${modelNameLowerCamel});
        if(b){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "修改信息")
    @PutMapping("/update")
    public R update(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        boolean b = ${modelNameLowerCamel}Service.update${modelNameUpperCamel}(${modelNameLowerCamel});

        if(b){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "删除信息（主键）")
    @DeleteMapping("/delete")
    public R delete(Integer id) {
        boolean b = ${modelNameLowerCamel}Service.deleteById(id);
        if(b){
            return R.ok();
        }
        return R.error();
    }
}
